import { createStore, applyMiddleware } from 'redux';
import loggerMiddleware from 'redux-logger';
import promiseMiddleware from 'redux-promise';
import thunkMiddleware from './middleware/thunk';
import { combineReducers } from 'redux';
import commonReducers from './reducer';

const reducers = combineReducers({
  ...commonReducers
});

const middlewares = ENABLE_REDUX_LOG
  ? [loggerMiddleware, thunkMiddleware, promiseMiddleware]
  : [thunkMiddleware, promiseMiddleware];

export default function configureStore(initialState) {
  const store = createStore(reducers, initialState, applyMiddleware(...middlewares));
  return store;
}
